package com.evolved.automata.experimental.tests;
import com.evolved.automata.experimental.*;
import com.evolved.automata.experimental.bots.*;
import com.evolved.automata.experimental.tools.*;


public class ProviderTests implements ConsoleLineInputReader {
	
	SRV1SensoryMotorProvider j_SRV1;
	AIInfoDisplay j_Display;
	public ProviderTests()
	{
		j_SRV1 = new SRV1SensoryMotorProvider();
		j_Display = new AIInfoDisplay("Info Display");
	}
	
	public static void main(String[] args)
	{
		
		ProviderTests tester;
		try
		{
			tester = new ProviderTests();
			tester.BeginTests();
		}
		catch (Exception e)
		{
			System.out.println(e.toString());
			System.exit(1);
		}
		System.exit(0);
	}
	
	public void BeginTests()
	{
		TestSRV1Provider();
	}
	private void TestSRV1Provider()
	{
		SimpleConsoleInterpreter interpreter;
		interpreter = new  SimpleConsoleInterpreter(this);
		
		j_Display.DisplayMessage("Starting SRV1 Info Console.\n");
		
		interpreter.Start();
	}

	@Override
	public boolean ProcessLine(String lineinput) {
		// TODO Auto-generated method stub
		int[] action = new int[1], data;
		String aname="";
		if (lineinput.length()>0)
		{
			if (lineinput.equalsIgnoreCase("i"))
			{
				action[0]=SRV1Robot.FORWARD;
				aname = "forward";
				
				
			} else if (lineinput.equalsIgnoreCase("k"))
			{
				
				action[0]=SRV1Robot.BACK;
				aname = "back";
			}
			else if (lineinput.equalsIgnoreCase("j"))
			{
				
				action[0]=SRV1Robot.LEFT;
				aname = "left";
			}
			else if (lineinput.equalsIgnoreCase("l"))
			{
				
				action[0]=SRV1Robot.RIGHT;
				aname = "right";
			}
			
			j_Display.DisplayMessageLine("Moving " + aname + " one step");
			j_SRV1.ApplyAction(action);
			
			data = j_SRV1.GetSensoryData();
			if (data!=null)
				j_Display.DisplayMessageLine("New Distance is: " + data[0]);
			else
				j_Display.DisplayMessageLine("Failure to get new distance");
			
			return true;
		}
		j_Display.DisplayMessageLine("Finished SRV1 tests");
		return false;
	}
	
}
